import requests
from api.login_api import Mepsking_Login
from common.utils import cs_data
from config import Base_Host
from id_and_name import IdName
class Add_Region:
    def add_region(self,Code,id):
        regionDto=[{"country":"{}".format(Code), "child": id}]
        return regionDto
    def get_data(self):
        test = cs_data()
        a = []
        for key, value in test.items():
            resp_01 = self.add_region(key, value)
            a.extend(resp_01)
        print('获取到的json-dict为：{}'.format(a))
        return a
    def region(self,name,token):
        url=Base_Host+'/api/product/shippingTemplate/update'
        json_dict=self.get_data()
        header_dict = {'accesstoken': token}
        json_dict01={"areaDtos":[{"country":"","id":0,"methodDtos":[{"areaId":0,"carryWay":"EXPEDITED","firstAmount":0,"firstWeight":1,"id":0,"secondAmount":0,"secondWeight":0,"minCondition":0}],"templateId":0,"areaName":"耗子喂汁","regin":"{}--".format(name),"regionDto":json_dict}],"defaultTemplate":True,"name":"马保国","id":"1622867817292795905"}
        resp=requests.post(url=url,headers=header_dict,json=json_dict01)
        print(resp.json())
        return resp
if __name__ == '__main__':
    login = Mepsking_Login()
    json_dict = {"password": "802545ba4ec603304d87afa3d818bf9a", "username": "2524726232@qq.com"}
    token = login.token(json_dict)
    name=IdName()
    name=name.name()
    add=Add_Region()
    test=add.region(name,token)
